package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.dto.QuestionFormDTO;
import com.tianji.learning.domain.query.QuestionPageQuery;
import com.tianji.learning.domain.vo.QuestionVO;
import com.tianji.learning.service.IInteractionQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 互动提问的问题表 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-04-02
 */
@RestController
@RequestMapping("/questions")
@Api(tags = "互动问题管理-用户端")
@RequiredArgsConstructor
@Slf4j
public class InteractionQuestionController {
    private final IInteractionQuestionService interactionQuestionService;

    @PostMapping()
    @ApiOperation("新增互动问题")
    public void addQuestion(@RequestBody @Validated QuestionFormDTO form) {
        interactionQuestionService.addQuestion(form);
    }
    @PutMapping("/{id}")
    @ApiOperation("修改互动问题")
    public void updateQuestion(@PathVariable("id") Long id, @RequestBody QuestionFormDTO form) {
        interactionQuestionService.updateQuestion(id,form);
    }
    @GetMapping("/page")
    @ApiOperation("分页查询互动问题-用户端")
    public PageDTO<QuestionVO> queryQuestionPage(QuestionPageQuery query) {
        return interactionQuestionService.queryQuestionByPage(query);
    }
    @GetMapping("/{id}")
    @ApiOperation("根据id查询问题详情")
    public QuestionVO queryQuestionById(@PathVariable("id") Long id) {
        log.info("查询问题详情，id={}",id);
        return interactionQuestionService.getQuestionById(id);
    }
    @DeleteMapping("/{id}")
    @ApiOperation("删除我的互动问题")
    public void deleteMyQuestion(@PathVariable("id") Long id) {
        interactionQuestionService.deleteMyQuestion(id);
    }
}
